
/**
 * Suggest help
 * 		tt = function (){////callback function
				alert($v("hiddenvalue"));
		}
		var param = {
			pageurl:"${path }/getDMK.do?dmk=xzqh&ajax=tt&dmklx=3&value=",//request url
			inputname:"suggestinput",// input name id
			divname:"showdiv",// show window name
			selfname:"testobj",// self obj name
			valuename:"hiddenvalue",//hidden id
			size:10,//show data record max number
			getDataFunc:tt//callback function
		}
		
	var testobj = new Suggest(param);
	<input type="text" name="suggestinput" id="suggestinput" value="" onkeyup="zy.resetReading()">
	<input type="hidden" name="hiddenvalue" id="hiddenvalue" value="">
	<iframe style="position:absolute;z-index:9;width:expression(this.nextSibling.offsetWidth);height:expression(this.nextSibling.offsetHeight);top:expression(this.nextSibling.offsetTop);left:expression(this.nextSibling.offsetLeft);" frameborder="0" ></iframe>
	<div id="showdiv" style="border:1px solid black;display:none;HEIGHT:200px;OVERFLOW:scroll;OVERFLOW-X:hidden;POSITION:absolute;Z-INDEX: 1;visibility: visible;"></div>
 */
var $j;if(!$j){$j = jQuery.noConflict()};
function Suggest(params){
	if(params){
		this.paramvalue=params.paramvalue;
		this.input = params.inputname;
		this.selfname=params.selfname;
		if(params.divname){
			this.showdiv = params.divname;
		}else{
			this.showdiv="div_"+this.input;
			if(document.all){
				document.writeln("<iframe style=\"position:absolute;z-index:9;width:expression(this.nextSibling.offsetWidth);height:expression(this.nextSibling.offsetHeight);top:expression(this.nextSibling.offsetTop);left:expression(this.nextSibling.offsetLeft);\" frameborder=\"0\" ></iframe>");
			}
			document.writeln("<div id=\"div_"+this.input+"\" style=\"border:1px solid black;width:0px;display:none;height:200px;overflow:scroll;overflow-x:hidden;position:absolute;z-index: 999;visibility: visible;\"></div>");
		}
		this.valuename=params.valuename;
		if(params.size){
			this.showsize=params.size;
		}else{
			this.showsize=30;
		}
		this.getDataFunc=params.getDataFunc;
	}else{
		alert('\u7f3a\u5c11\u5fc5\u8981\u7684\u53c2\u6570\uff01\n{\n\tpageurl:"index.jsp?value=",\n\tinputname:"inputid",\n\t[divname:"showdivid",]\n\tselfname:"objectname",\n\t[size:20],\n\t[split:{\n\t\tone:"||",\n\t\ttwo:"::"\n\t}],\n\t[backcall:backcallfunction,]\n\t[valuename:hiddeninputname]\n}');	
	}
	this.currentInfo = "";             
	this.counter = 1;                 
	this.isReading = true;            
	this.isOpen = false;				
	this.selectNum = 0;					
	this.count = 0;						
}
Suggest.prototype.addparams =function (param) {
	this.paramvalue+=param;
}

Suggest.prototype.readInfo =function () {
	this.isReading=false;

	if (this.currentInfo == this.getInputValue() && this.getInputValue()) {
		this.counter++;
	} else {
		this.currentInfo = this.getInputValue();
		this.setValue(this.valuename,"");
		this.counter = 0;
	}

	if (this.counter ==2) {
		this.getSuggest();  
	} else {
		setTimeout(this.selfname+".readInfo()",400);  
	}
}


Suggest.prototype.getSuggest=function () {
	var selfobj = this;
	if(this.getDataFunc.indexOf('()')){
		this.getDataFunc=this.getDataFunc.replace('()','(');
	}else{
		this.getDataFunc=this.getDataFunc.replace(')',',');
	}
	eval(this.getDataFunc+"'"+this.getInputValue()+"',function(data){selfobj.showSuggest(data);})");
}

Suggest.prototype.getInputValue=function () {
	return this.getValue(this.input);
}

Suggest.prototype.showSuggest=function(data) {

		if(data&&data.length>0){
				this.hiddenSuggest();     
				this.count = data.length;
            	
                for (var i = 0; i < data.length; i++) {
					 if(this.valuename){
							this.createSuggest(data[i].name, i + 1,data[i].id);  
					}else{
						this.createSuggest(data[i].name, i + 1,""); 
					}
					if(i==this.showsize-1){
						this.count = this.showsize;
						this.createSuggest("\u663e\u793a"+this.showsize+"\u6761,\u5171"+data.length+"\u6761\u8bb0\u5f55", i + 1,"",true);
						break;
					}
				}
            	if(data.length==1){
            	     this.selectNum=1;
            	     this.setSuggest();
            	}else{
				     this.displaySuggest();
            	}
			} else {
				this.hiddenSuggest();
			}
}


Suggest.prototype.createSuggest=function(text, i,value,flag) {
	if(this.count==0){
		var sDiv = "<div id='" +  this.showdiv + i + "' style=\"width:100%;white-space:nowrap;color:#ff0000;\">" + text + "</div>";
	}else{
		if(flag){
			var sDiv = "<div id='" +  this.showdiv+ (i+1)+"' style=\"width:100%;white-space:nowrap;color:#00ff00;\">" + text + "</div>";
		}else{
			var sDiv = "<div id='" +  this.showdiv + i + "' style='width:100%;white-space:nowrap;' onmouseover=\""+this.selfname+".mouseOver(this)\"" + " onclick='"+this.selfname+".setSuggest("+i+")'>";
			sDiv+=text + "</div>"
			if(this.valuename){
		 		sDiv+="<input type='hidden' name='"+this.valuename+i+"' id='"+this.valuename+i+"' value='"+value+" '/>";
			}
		}
	}
	
	this.setHtml(this.showdiv,this.getHtml(this.showdiv)+sDiv);
}


Suggest.prototype.setSuggest=function() {
	if(this.selectNum>0){
	    this.currentInfo= this.getHtml(this.showdiv+this.selectNum);
		this.setValue((this.input),this.getHtml(this.showdiv+this.selectNum));
		if(this.valuename){
		     this.setValue(this.valuename,this.getValue(this.valuename+this.selectNum));
		}
		if(this.backcall){
			this.backcall();
		}
		this.hiddenSuggest(true);
	}else{
		this.hiddenSuggest();
	}
}

Suggest.prototype.setDown=function () {
	if (this.selectNum == 0) {
		this.selectNum = this.selectNum + 1;
		this.setOverStyle();
	} else {
		if (this.selectNum < this.count) {
			this.setOutStyle();
			this.selectNum = this.selectNum + 1;
			this.setOverStyle();
		} else {
			this.setOutStyle();
			this.selectNum = 0;
		}
	}
}

Suggest.prototype.setOverStyle=function () {
	with (this.getObject(this.showdiv + this.selectNum)) {
		style.background = "#0072e3";
		style.cursor = "hand";
		style.color = "#ffffff";
	}
}

Suggest.prototype.setOutStyle=function () {
	with (this.getObject(this.showdiv + this.selectNum)) {
		style.background = "#ffffff";
		style.color = "#000000";
	}
}

Suggest.prototype.setUp=function() {
	if (this.selectNum == 0) {
		this.selectNum = this.count;
		 this.setOverStyle();
	} else {
		if (this.selectNum == 1) {
			 this.setOutStyle();
			this.selectNum = 0;
		} else {
			 this.setOutStyle();
			this.selectNum = this.selectNum - 1;
			 this.setOverStyle();
		}
	}
}

Suggest.prototype.mouseOver=function (a) {
	if (this.selectNum != 0) {
		 this.setOutStyle();
	}
	this.selectNum = parseInt(a.id.substring(this.showdiv.length));
	this.setOverStyle();
}

Suggest.prototype.resetReading=function () {
	if (this.isOpen) {
  		//bottom40top38left37right39home36end35pageup33pagedown34 enter13 Ctrl17 Alt18 Win91 Edit93 Shift16 CapsLock20 F5116 F9120 ESC27
		switch (event.keyCode) {
		  case 38:
			this.setUp();
			break;
		  case 40:
			this.setDown();
			break;
		  case 33:
			this.setUp();
			break;
		  case 34:
			this.setDown();
			break;
		  case 36:
			this.setUp();
			break;
		  case 35:
			this.setDown();
			break;
		  case 13://回车
			this.setSuggest();
			break;
		  case 27://ESC
			this.hiddenSuggest();
			break;
			default:break;
		}
	}
	this.counter=0;
	if (this.isReading) {
		
		this.readInfo(event);
	}
}


Suggest.prototype.displaySuggest=function () {
	this.isOpen = true;
	oRect = this.getObject(this.input).getBoundingClientRect();
	with (this.getObject(this.showdiv)) {
		style.display = "";
		style.position = "absolute";
		style.top = oRect.top + this.getObject(this.input).offsetHeight - this.getObject(this.input).clientTop;
		style.left = oRect.left - this.getObject(this.input).clientLeft;
		if(this.getObject(this.showdiv).offsetWidth<this.getObject(this.input).offsetWidth){
			style.width = this.getObject(this.input).offsetWidth;
		}
	}
}


Suggest.prototype.hiddenSuggest=function (flag) {
	this.getObject(this.showdiv).style.display = "none";
	this.clearSuggest(flag);
}
Suggest.prototype.closeReading=function () {
    this.setSuggest();
	this.hiddenSuggest();
	this.isReading = false;
}

Suggest.prototype.clearSuggest=function (flag) {
	this.count = 0;
	if(!flag&&this.valuename){
		this.setValue(this.valuename,"");
	}
	this.selectNum = 0;
	this.isReading = true;
	this.isOpen = false;
	this.setHtml(this.showdiv,"");
}

Suggest.prototype.getHtml=function(name){
	return $j('#'+name).html();
}
Suggest.prototype.setHtml=function(name,html){
	$j('#'+name).html(html);
}
Suggest.prototype.getValue=function(name){
	return $j('#'+name).val();
}
Suggest.prototype.setValue=function(name,value){
	$j('#'+name).val(value);
}
Suggest.prototype.getObject=function(name){
	return $j('#'+name).get(0);
}